<?php echo $this->fetch('header.html'); ?>
<script type="text/javascript">
$(function(){
    $('#article_form').validate({
        errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
        },
        success       : function(label){
            label.addClass('right').text('OK!');
        },
        rules : {    
            title : {
                required : true
            },
            cate_id :{
                required : true
            },
            link    :{
                url     : true
            },
            sort_order:{
               number   : true
            }
        },
        messages : {
            title : {
                required : '文章标题不能为空'
            },
            cate_id : {
                required : '文章分类不能为空'
            },
            link    : {
                url     : '请输入有效的链接地址'
            },
            sort_order  : {
                number   : '此项必须为数字'
            }
        }
    });
});

function add_uploadedfile(file_data)
{
    var newImg = '<tr id="' + file_data.file_id + '" class="tatr2"><input type="hidden" name="file_id[]" value="' + file_data.file_id + '" /><td><img width="40px" height="40px" src="' + SITE_URL + '/' + file_data.file_path + '" /></td><td>' + file_data.file_name + '</td><td><a href="javascript:insert_editor(\'' + file_data.file_name + '\', \'' + file_data.file_path + '\');">插入编辑器</a> | <a href="javascript:drop_uploadedfile(' + file_data.file_id + ');">删除</a></td></tr>';
    $('#thumbnails').prepend(newImg);
}
function insert_editor(file_name, file_path){
    tinyMCE.execCommand('mceInsertContent', false, '<img src="'+ SITE_URL +'/' + file_path + '" alt="'+ file_name + '">');
}
function drop_uploadedfile(file_id)
{
    if(!window.confirm(lang.uploadedfile_drop_confirm)){
        return;
    }
    $.getJSON('index.php?app=article&act=drop_uploadedfile&file_id=' + file_id, function(result){
        if(result.done){
            $('#' + file_id).remove();
        }else{
            alert('drop_error');
        }
    });
}
</script>
<?php echo $this->_var['build_editor']; ?>
<?php echo $this->_var['build_upload']; ?>
<div id="rightTop">
    <p>文章管理</p>
    <ul class="subnav">
        <li><a class="btn1" href="index.php?app=article">管理</a></li>
        <?php if ($this->_var['article']['article_id']): ?>
        <li><a class="btn1" href="index.php?app=article&amp;act=add">新增</a></li>
        <?php else: ?>
        <li><span>新增</span></li>
        <?php endif; ?>
    </ul>
</div>

<div class="info">
    <form method="post" enctype="multipart/form-data" id="article_form">
        <table class="infoTable">
            <tr>
                <th class="paddingT15">
                    标题:</th>
                <td class="paddingT15 wordSpacing5">
                    <input class="infoTableInput" id="title" type="text" name="title" value="<?php echo htmlspecialchars($this->_var['article']['title']); ?>" />
                </td>
            </tr>
            <?php if (! $this->_var['article']['code']): ?>
            <tr>
                <th class="paddingT15">
                    <label for="cate_id">所属分类:</label></th>
                <td class="paddingT15 wordSpacing5">
                    <select id="cate_id" name="cate_id"><option value="">请选择...</option><?php echo $this->html_options(array('options'=>$this->_var['parents'],'selected'=>$this->_var['article']['cate_id'])); ?></select>
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    链接:</th>
                <td class="paddingT15 wordSpacing5">
                    <input class="infoTableInput" id="link" type="text" name="link" value="<?php echo htmlspecialchars($this->_var['article']['link']); ?>" />
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    <label for="if_show">显示:</label></th>
                <td class="paddingT15 wordSpacing5">
                    <input id="yes" type="radio" name="if_show" value="1" <?php if ($this->_var['article']['if_show'] == 1): ?> checked="checked"<?php endif; ?> />
                    <label for="yes">是</label>
                    <input id="no" type="radio" name="if_show" value="0" <?php if ($this->_var['article']['if_show'] == 0): ?> checked="checked"<?php endif; ?> />
                    <label for="no">否</label>
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    排序:</th>
                <td class="paddingT15 wordSpacing5">
                    <input class="sort_order" id="sort_order" type="text" name="sort_order" value="<?php echo $this->_var['article']['sort_order']; ?>" />
                </td>
            </tr>
            <?php endif; ?>
            <tr>
                <th class="paddingT15">
                    <label for="article">文章内容:</label></th>
                <td class="paddingT15 wordSpacing5">
				<script type="text/javascript" charset="utf-8" src="/data/ueditor/ueditor.config.js"></script>
				<script type="text/javascript" charset="utf-8" src="/data/ueditor/ueditor.all.min.js"> </script>
				<script type="text/javascript" charset="utf-8" src="/data/ueditor/lang/zh-cn/zh-cn.js"></script>
                <textarea name="content" id="content" style="width:98%;height:500px;"><?php echo htmlspecialchars($this->_var['article']['content']); ?></textarea>
                <script type="text/javascript">var ue = UE.getEditor('content');</script>                
                </td>
            </tr>
          <tr>
              <th>添加时间：</th>
              <td class="ptb20"><input type="text" name="add_time" value="<?php echo local_date("Y-m-d H:i:s",$this->_var['article']['add_time']); ?>" /></td>
          </tr>
          <tr>
            <th></th>
            <td class="ptb20">
                <input class="formbtn" type="submit" name="Submit" value="提交" />
                <input class="formbtn" type="reset" name="Submit2" value="重置" />
            </td>
        </tr>
        </table>
    </form>
</div>
<?php echo $this->fetch('footer.html'); ?>
